﻿#region File and License Information
/*
<File>
	<License Type="BSD">
		Copyright © 2009 - 2012, Outcoder. All rights reserved.
	
		This file is part of Calcium (http://calciumsdk.net).

		Redistribution and use in source and binary forms, with or without
		modification, are permitted provided that the following conditions are met:
			* Redistributions of source code must retain the above copyright
			  notice, this list of conditions and the following disclaimer.
			* Redistributions in binary form must reproduce the above copyright
			  notice, this list of conditions and the following disclaimer in the
			  documentation and/or other materials provided with the distribution.
			* Neither the name of the <organization> nor the
			  names of its contributors may be used to endorse or promote products
			  derived from this software without specific prior written permission.

		THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
		ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
		WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
		DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
		DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
		(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
		LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
		ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
		SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	</License>
	<Owner Name="Daniel Vaughan" Email="danielvaughan@outcoder.com" />
	<CreationDate>2009-04-15 21:44:59Z</CreationDate>
</File>
*/
#endregion

using System;
using Outcoder.IO;

namespace Outcoder.IO
{
	/// <summary>
	/// Used to invoke a file operation that works upon a file
	/// with the specified <code>fileName</code>.
	/// </summary>
	public delegate void FileOperationHandler(string fileName);
}

namespace Outcoder.Services
{
	/// <summary>
	/// Allows for the loading and saving of file content
	/// using delegates for invocation.
	/// </summary>
	public interface IFileService
	{
		/// <summary>
		/// Prompts the user for a file name and attempts 
		/// to invoke the specified operationHandler.
		/// <seealso cref="Save"/>
		/// </summary>
		/// <param name="fileName">Default name of the file to suggest to the user. 
		/// Can be null.</param>
		/// <param name="operationHandler">The operation handler 
		/// that carries out the actual save operation.</param>
		/// <param name="fileErrorAction">The file error action. What to do if the operation fails. 
		/// <see cref="FileErrorAction"/></param>
		/// <returns>The result of the operation indicating whether the Save was successful etc.</returns>
		/// <exception cref="ArgumentNullException">
		/// Occurs if the specified <code>operationHandler</code> is null.</exception>
		FileOperationResult SaveAs(string fileName, FileOperationHandler operationHandler,
								   FileErrorAction fileErrorAction);

		/// <summary>
		/// Invokes the specified FileOperationHandler using the specified fileName. 
		/// If the specified <code>FileErrorAction</code> is <code>UseAlternative</code>
		/// and the operation fails then the user will be prompted once 
		/// to select another file. 
		/// </summary>
		/// <param name="fileName">The name that is passed to the specified operationHandler.</param>
		/// <param name="operationHandler">The handler that carries out the actual save operation.</param>
		/// <param name="fileErrorAction">The file error action. 
		/// That is, what to do if the operation fails.</param>
		/// <returns>The result of the operation indicating whether the Save was successful etc.</returns>
		/// <exception cref="ArgumentNullException">
		/// Occurs if the specified <code>operationHandler</code> is <code>null</code>.</exception>
		FileOperationResult Save(string fileName, FileOperationHandler operationHandler,
								 FileErrorAction fileErrorAction);

		/// <summary>
		/// Opens a file using the specified operation handler.
		/// </summary>
		/// <param name="operationHandler">The operation handler. 
		/// The handler that carries out the actual opening of the file.</param>
		/// <param name="fileErrorAction">The file error action. 
		/// This indicates what to do if an exception is thrown while opening the file.</param>
		/// <param name="dialogFilter">The dialog filter to display in the open file dialog.</param>
		/// <returns>The result of the operation indicating whether opening 
		/// of the file was successful etc.</returns>
		FileOperationResult Open(FileOperationHandler operationHandler,
								 FileErrorAction fileErrorAction, string dialogFilter);

		/// <summary>
		/// Opens a file using the specified operation handler.
		/// </summary>
		/// <param name="fileName">The path to the file that is to be opened.</param>
		/// <param name="operationHandler">The operation handler. 
		/// The handler that carries out the actual opening of the file.</param>
		/// <param name="fileErrorAction">The file error action. 
		/// This indicates what to do if an exception is thrown while opening the file.</param>
		/// <param name="dialogFilter">The dialog filter to display in the open file dialog.</param>
		/// <returns>The result of the operation indicating whether opening 
		/// of the file was successful etc.</returns>
		FileOperationResult Open(string fileName, FileOperationHandler operationHandler,
			FileErrorAction fileErrorAction, string dialogFilter);
	}
}
